<template>
  <table>
    <thead>
      <tr>
        <th v-for="column in columns" :key="column.key">{{ column.title }}</th>
      </tr>
    </thead>
    <tbody>
      <tr v-for="(row, rowIndex) in data" :key="rowIndex">
        <th v-for="col in columns" :key="col.key">
          <template v-if="'render' in col">
            <Render :row="row" :column="col" :index="rowIndex" :render="col.render" />
          </template>
          <template v-else-if="'slot' in col">
            <!-- <slot :row="row" :column="col" :index="rowIndex" :render="col.render"></slot> -->
            <slot-scope :row="row" :column="col" :index="rowIndex" />
          </template>
          <template v-else>
            {{ row[col.key] }}
          </template>
        </th>
      </tr>
    </tbody>
  </table>
</template>

<script>
import Render from './render.js'
import SlotScope from './slot.js'
export default {
  props: {
    columns: {
      type: Array,
      default: () => [],
    },
    data: {
      type: Array,
      default: () => [],
    },
  },
  provide() {
    return {
      tableRoot: this,
    }
  },
  data() {
    return {}
  },
  components: { Render, SlotScope },
}
</script>

<style lang="scss" scoped>
table {
  width: 100%;
  border-collapse: collapse;
  border-spacing: 0;
  empty-cells: show;
  border: 1px solid #e9e9e9;
}
table th {
  background: #f7f7f7;
  color: #5c6b77;
  font-weight: 600;
  white-space: nowrap;
}
table td,
table th {
  padding: 8px 16px;
  border: 1px solid #e9e9e9;
  text-align: left;
}
</style>
